package ari.com.messaging.queue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

public class QueueImpl<T> implements Queue<T> {
	private static final int TIMEOUT = 5000;
	BlockingQueue<T> queue = new LinkedBlockingQueue<T>();

	@Override
	public T deQueue() {
		T message = null;
		try {
			message = queue.poll(TIMEOUT, TimeUnit.MILLISECONDS);
		} catch (final InterruptedException e) {
			e.printStackTrace();
		}
		return message;
	}

	@Override
	public void enQueue(final T message) {
		try {
			queue.offer(message, TIMEOUT, TimeUnit.MILLISECONDS);
		} catch (final InterruptedException e) {
			e.printStackTrace();
		}

	}

	@Override
	public T peek() {
		final T message = queue.peek();
		return message;
	}

}
